package com.yy.train.ticket.train.controller;

import java.util.Arrays;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.train.ticket.into.page.LinePage;
import com.yy.train.ticket.into.RunDate;
import com.yy.train.ticket.into.page.RunDatePage;
import com.yy.train.ticket.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TtTrainRunDateEntity;
import com.yy.train.ticket.train.service.TtTrainRunDateService;




/**
 * 车次日期
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-27 10:03:48
 */
@RestController
@RequestMapping("tt/rundate")
public class TtTrainRunDateController {
    @Autowired
    private TtTrainRunDateService ttTrainRunDateService;


    @PostMapping("/page")
    public R page(@RequestBody RunDatePage trainPage){

        LambdaQueryWrapper<TtTrainRunDateEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(StringUtils.checkValNotNull(trainPage.getNumberId()),TtTrainRunDateEntity::getNumberId,trainPage.getNumberId());
        Page<TtTrainRunDateEntity> pages = new Page<TtTrainRunDateEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtTrainRunDateEntity> iPage = ttTrainRunDateService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam  Long numberId){

        return R.ok(this.ttTrainRunDateService.list(Wrappers.<TtTrainRunDateEntity>lambdaQuery().eq(TtTrainRunDateEntity::getNumberId,numberId)));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{runDateId}")
    public R info(@PathVariable("runDateId") Integer runDateId){
		TtTrainRunDateEntity ttTrainRunDate = ttTrainRunDateService.getById(runDateId);

        return R.ok(ttTrainRunDate);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody RunDate trainNumber){
        return ttTrainRunDateService.saveRunDate(trainNumber);


    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TtTrainRunDateEntity ttTrainRunDate){
		ttTrainRunDateService.updateById(ttTrainRunDate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] runDateIds){
		ttTrainRunDateService.removeByIds(Arrays.asList(runDateIds));

        return R.ok();
    }

}
